package com.ict.web.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.api.client.util.Lists;
import com.ict.common.utils.DateUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.domain.PerformanceRule;
import com.ict.web.dto.InsertPerformanceRuleDto;
import com.ict.web.mapper.PerformanceRuleMapper;
import com.ict.web.service.IPerformanceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 绩效Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-15
 */
@Service
public class PerformanceRuleServiceImpl extends ServiceImpl<PerformanceRuleMapper, PerformanceRule> implements IPerformanceRuleService
{
    @Autowired
    private PerformanceRuleMapper performanceRuleMapper;

    /**
     * 指标规则列表
     * @return
     */
    @Override
    public List<PerformanceRule> selectPerformanceRuleList() {
        return performanceRuleMapper.selectPerformanceRuleList();
    }

    /**
     * 新增指标规则
     * @param indicatorsId
     * @param addDtoS
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertPerformanceRule(Long indicatorsId,List<InsertPerformanceRuleDto> addDtoS){

    if (!CollectionUtils.isEmpty(addDtoS)){
        List<PerformanceRule> beans = Lists.newArrayList();
        for(InsertPerformanceRuleDto performanceRule:addDtoS){
            beans.add(new PerformanceRule(IdUtils.snowId(),indicatorsId,performanceRule.getRegulation(),Double.valueOf(performanceRule.getValue()),
                    performanceRule.getScore(),PerformanceRule.DELETE_STATUS_NORMAL,DateUtils.getNowDate(),DateUtils.getNowDate()));
        }

         this.saveBatch(beans);
    }

    }

    /**
     * 逻辑删除
     * @param ruleId
     * @return
     */
    @Override
    public int deletePerformanceRuleById(Long ruleId) {
        return performanceRuleMapper.deletePerformanceRuleByRuleId(ruleId);
    }
}
